import cv2 as cv
from testshape import top, bottom, left, right
from filter import depth_inpaint, depth_medianblur, joint_filter

print('Depth map inpaint code.')
img = cv.imread('D:/cpx_0009.png', -1)
imgrgb = cv.imread('D:/cpx_00091.png')
assert img is not None, 'Image does not exit.'
t, b, l, r = top(img), bottom(img), left(img), right(img)
img = img[t:b+1, l:r+1]
imgrgb = imgrgb[t:b+1, l:r+1]
imgshow = (img/12+0.5).astype('uint8')
cv.imshow('crop', imgshow)
cv.waitKey(10)
del t, b, l, r

# 选择滤波方法
dst1 = depth_inpaint(img)
# dst2 = depth_medianblur(img)
# dst3 = joint_filter(img, imgrgb)

cv.imshow('inpaint', (dst1/12+0.5).astype('uint8'))
# cv.imshow('medianblur', (dst2/12+0.5).astype('uint8'))
# cv.imshow('jointfilter', (dst3/12+0.5).astype('uint8'))
cv.waitKey(0)
# scale = (dst.max() - dst.min()) / 256
# imgshow = ((dst - dst.min()) / scale+0.5).astype('uint8')
# imgshow = cv.equalizeHist(imgshow)
# cv.imshow('equalizeHist', imgshow)
